<template>
  <div class="p-15 p-t-0">
    <div class="table-padding orderDialog">
      <el-form :model="modelForm" ref="modelForm">
        <div>
          <el-row>
            <el-col :span="7">
              <el-form-item prop="supplier" :rules="[]">
                <div class="el-input el-input-group el-input-group--prepend">
                  <div class="el-input-group__prepend">供应商</div>
                  <el-select v-model="modelForm.supplierName" size="medium" filterable placeholder="请选择供应商"
                             :disabled="isEdit" style="width: 100%">
                    <el-option
                      v-for="item in suppliers"
                      :key="item.id"
                      :label="item.name"
                      :disabled="(item.state && item.state.key!='NORMAL')"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="1">
              <el-form-item prop="no" :rules="[]">
                <div class="el-input el-input-group el-input-group--prepend">
                  <div class="el-input-group__prepend">订单日期</div>
                  <el-date-picker size="medium"
                                  v-model="modelForm.purchaseTime"
                                  type="date"
                                  style="width: 100%"
                                  format="yyyy-MM-dd"
                                  value-format="yyyy-MM-dd"
                                  placeholder="选择日期"
                                  :readonly="true"
                                 >
                  </el-date-picker>
                </div>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="7">
              <el-form-item prop="branchName" :rules="[]">
                <el-input placeholder="请输入采购门店" v-model="modelForm.branchName" size="medium" :maxLength="20">
                  <template slot="prepend">
                      <el-button tabIndex="-1">采购门店</el-button>
                  </template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="1">
              <el-form-item prop="stockName" :rules="[]">
                <el-input placeholder="请输入收货仓库" v-model="modelForm.warehouseName" size="medium" :maxLength="20">
                  <template slot="prepend">
                    <el-button tabIndex="-1">收货仓库</el-button>
                  </template>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>

            <el-col :span="6" :offset="2">
            </el-col>
          </el-row>
          <el-form-item prop="no" :rules="[]">
            <el-input type="text" size="medium" v-model="modelForm.address" :disabled="isEdit" auto-complete="off"
                      placeholder="请输入收货地址">
              <template slot="prepend">
                <el-button>收货地址</el-button>
              </template>
            </el-input>
          </el-form-item>
          <el-form-item prop="no" :rules="[]">
            <el-input type="text" size="medium" v-model="modelForm.remark" :disabled="isEdit" auto-complete="off"
                      placeholder="请输入备注信息">
              <template slot="prepend">
                <el-button>备注</el-button>
              </template>
            </el-input>
          </el-form-item>
        </div>
        <div class="orderTable">
          <el-form-item class="text-left text-left1">
            <el-button size="medium" type="primary" @click="submitForm('modelForm')"><i class="icon icon-baocun"></i> 保存
            </el-button>
            <el-button size="medium" class="m-l-0" type="success" @click="resetForm('modelForm')"><i
              class="icon icon-tijiao"></i> 提交并审核
            </el-button>
            <!--<el-button size="medium" type="warning" v-if="modelForm.id" @click="printOrder"><i-->
              <!--class="icon icon-dayin"></i> 打印-->
            <!--</el-button>-->
            <el-button size="medium" type="danger" @click="goBack()"><i class="icon icon-fanhui1"></i> 取消</el-button>
          </el-form-item>
          <el-form-item class="text-left text-left5">
            <el-button size="medium" type="warning" @click="printOrder"><i class="icon icon-dayin"></i> 打印</el-button>
            <el-button size="medium" type="danger" @click="goBack()"><i class="icon icon-fanhui1"></i> 取消</el-button>
          </el-form-item>
          <!--审核|未审核 start-->
          <div v-if="modelForm.state=='NOAUDIT' || modelForm.state=='AUDIT'">
            <el-table
              :data="tableData"
              border
              show-summary
              :summary-method="getSummaries"
              style="width: 100%">
              <el-table-column
                type="index"
                width="50">
              </el-table-column>
              <el-table-column
                width="80">
                <template  slot-scope="scope">
                <span class="el-icon-plus" style="cursor: pointer;font-size: 10px;padding-right: 5px"
                      @click="addColumn(scope.$index)"></span>
                  <span class="el-icon-minus" style="cursor: pointer;font-size: 10px;padding-left: 5px"
                        @click="minusColumn(scope.$index)"></span>
                </template>
              </el-table-column>
              <el-table-column
                prop="code"
                label="原料编号"
                width="150">
                <template  slot-scope="scope">
                  <div style="position: relative">
                    <el-select v-model="scope.row.code" :disabled="isEdit" remote @change="codeChange(scope.$index)"   :remote-method="remoteMethod"
                               filterable="" allow-create placeholder="请输入原料编号">
                      <el-option v-for="(item,index) in material" :disabled="(item.state && item.state.key!='NORMAL')" :key="index"
                                 :label="item.code" :value="item.no">
                        <div style="width:100px;border-bottom:1px solid #c0c0c0;padding:5px 0px">
                          {{item.value}}[{{item.purchaseUnit}}]
                        </div>
                      </el-option>
                    </el-select>
                    <span class="el-icon-more" @click="handleIconClick(scope.$index)"
                          style="cursor: pointer;font-size: 10px;padding-right: 5px; position: absolute;right: 10px;top: 40%"></span>
                  </div>
                </template>
              </el-table-column>
              <el-table-column
                prop="name"
                label="原料名称"
                width="250">
              </el-table-column>
              <el-table-column
                prop="purchaseSpec"
                label="规格型号"
                width="80">
              </el-table-column>
              <el-table-column
                prop="spec"
                label="采购规格"
                width="100">
              </el-table-column>
              <el-table-column
                prop="unitName"
                label="采购单位"
                width="100">
              </el-table-column>
              <el-table-column
                prop="purchaseCount"
                label="采购数量"
                width="150">
                <template  slot-scope="scope">
                  <el-input v-model="scope.row.purchaseCount" :disabled="isEdit" @blur="priceValidate(scope.row,'purchaseCount')" @focus="printNum()"
                            placeholder="0.00"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="purchasePrice"
                label="采购单价"
                width="150">
                <template  slot-scope="scope">
                  <el-input v-model="scope.row.purchasePrice" :disabled="isEdit" @blur="priceValidate(scope.row,'purchasePrice')" @focus="printNum()"
                            placeholder="0.00"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="purchaseNewPrice"
                label="历史采购单价"
                width="150">
                <template  slot-scope="scope">
                  <span>{{scope.row.purchaseNewPrice | money}}</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="purchaseAmount"
                label="采购金额"
                width="150">
                <template  slot-scope="scope">
                    {{scope.row.purchaseAmount}}
                </template>
              </el-table-column>
              <el-table-column
                prop="groupRemark"
                label="总部备注">
                <template  slot-scope="scope">
                  <el-input v-model="scope.row.groupRemark" :disabled="isEdit" placeholder=""></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="branchRemark"
                label="门店备注">
                <template  slot-scope="scope">
                  <el-input v-model="scope.row.branchRemark" :disabled="isEdit" placeholder=""></el-input>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <!--审核|未审核 end-->
          <!--已收货|已完成 start-->
          <div v-if="modelForm.state=='DELIVERED' || modelForm.state=='COMPLETED'">
            <el-table
              :data="tableData"
              border
              show-summary
              :summary-method="getSummaries1"
              style="width: 100%">
              <el-table-column
                type="index"
                width="50">
              </el-table-column>
              <el-table-column
                width="80">
                <template  slot-scope="scope">
                <span class="el-icon-plus" style="cursor: pointer;font-size: 10px;padding-right: 5px"
                      @click="addColumn(scope.$index)"></span>
                  <span class="el-icon-minus" style="cursor: pointer;font-size: 10px;padding-left: 5px"
                        @click="minusColumn(scope.$index)"></span>
                </template>
              </el-table-column>
              <el-table-column
                prop="code"
                label="原料编号"
                width="150">
                <template  slot-scope="scope">
                  <div style="position: relative">
                    <el-select v-model="scope.row.code" :disabled="isEdit" remote @change="codeChange(scope.$index)"   :remote-method="remoteMethod"
                               filterable="" allow-create placeholder="请输入原料编号">
                      <el-option v-for="(item,index) in material" :disabled="(item.state && item.state.key!='NORMAL')" :key="index"
                                 :label="item.code" :value="item.no">
                        <div style="width:100px;border-bottom:1px solid #c0c0c0;padding:5px 0px">
                          {{item.value}}[{{item.purchaseUnit}}]
                        </div>
                      </el-option>
                    </el-select>
                    <span class="el-icon-more" @click="handleIconClick(scope.$index)"
                          style="cursor: pointer;font-size: 10px;padding-right: 5px; position: absolute;right: 10px;top: 40%"></span>
                  </div>
                </template>
              </el-table-column>
              <el-table-column
                prop="name"
                label="原料名称"
                width="250">
              </el-table-column>
              <el-table-column
                prop="spec"
                label="规格型号"
                width="80">
              </el-table-column>
              <el-table-column
                prop="purchaseSpec"
                label="采购规格"
                width="100">
              </el-table-column>
              <el-table-column
                prop="unitName"
                label="采购单位"
                width="100">
              </el-table-column>
              <el-table-column
                prop="purchaseCount"
                label="采购数量"
                width="150">
                <template  slot-scope="scope">
                  <el-input v-model="scope.row.purchaseCount" :disabled="isEdit" @blur="priceValidate(scope.row,'purchaseCount')" @focus="printNum()"
                            placeholder="0.00"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="purchasePrice"
                label="采购单价"
                width="150">
                <template  slot-scope="scope">
                  <el-input v-model="scope.row.purchasePrice" :disabled="isEdit" @blur="priceValidate(scope.row,'purchasePrice')" @focus="printNum()"
                            placeholder="0.00"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="purchaseAmount"
                label="采购金额"
                width="150">
                <template  slot-scope="scope">
                  {{scope.row.purchaseAmount | money}}
                </template>
              </el-table-column>

              <el-table-column
                prop="sendCount"
                label="发货数量"
                width="150">
                <template  slot-scope="scope">
                  <el-input v-model="scope.row.sendCount" :disabled="isEdit" @blur="priceValidate(scope.row,'sendCount')" @focus="printNum()"
                            placeholder="0.00"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="sendPrice"
                label="发货单价"
                width="150">
                <template  slot-scope="scope">
                  <el-input v-model="scope.row.sendPrice" :disabled="isEdit" @blur="priceValidate(scope.row,'sendPrice')" @focus="printNum()"
                            placeholder="0.00"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="sendAmount"
                label="发货金额"
                width="150">
                <template  slot-scope="scope">
                  {{scope.row.sendAmount | money}}
                </template>
              </el-table-column>

              <el-table-column
                prop="acceptCount"
                label="门店收货数量"
                width="150">
                <template  slot-scope="scope">
                  <el-input v-model="scope.row.acceptCount" :disabled="isEdit" @blur="priceValidate(scope.row,'acceptCount')" @focus="printNum()"
                            placeholder="0.00"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="acceptPrice"
                label="门店收货单价"
                width="150">
                <template  slot-scope="scope">
                  <el-input v-model="scope.row.acceptPrice" :disabled="isEdit" @blur="priceValidate(scope.row,'acceptPrice')" @focus="printNum()"
                            placeholder="0.00"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="acceptAmount"
                label="门店收货金额"
                width="150">
                <template  slot-scope="scope">
                  {{scope.row.acceptAmount | money}}
                </template>
              </el-table-column>

              <el-table-column
                prop="groupRemark"
                label="总部备注">
                <template  slot-scope="scope">
                  <el-input v-model="scope.row.groupRemark" :disabled="isEdit" placeholder=""></el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="branchRemark"
                label="门店备注">
                <template  slot-scope="scope">
                  <el-input v-model="scope.row.branchRemark" :disabled="isEdit" placeholder=""></el-input>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <!--已收货|已完成 end-->


        </div>
      </el-form>

    </div>
    <materials-select :isShow="dialogTableVisible"  v-on:pushData="getData" v-on:closeDialog="dialogTableVisible=false"></materials-select>
  </div>
</template>
<script>
  //注意路径
  import materialsSelect from "@/components/materialsSelect.vue"
  export default {
    data() {
      return {
        dialogTableVisible: false,
        isEdit: false,
        type:1,
        tableData: [{
          id: "",
          code: '',
          name: '',
          goodsSpec: '',
          purchaseSpec: '',
          unitName: '',
          count: '0',
          price: '0.00',
          purchaseNewPrice: '',
          money: '0.00',
          memo: '',}],

        modelForm: {
          createAt:""
        },
        currentPage3:3,
        pageSizeSet: window.pageSizes,
        pageSize: window.pageSize,
        pageTotal: 10,
        material: [],
        supplier: "",
        content: "",
        warehouse: "",
        suppliers: [],
        warehouses: [],
        restaurants: [],
        timeout: null,
        gridData: [],
        itemActive: 0,
        data: [],
        selectRow: [],
        inputText: "",
        defaultProps: {
          children: 'children',
          label: 'label'
        },
        pickerOptions0: {
          disabledDate(time) {
            return time.getTime() < Date.now() - 8.64e7;
          }
        },
      }
    },
    components: {
      materialsSelect
    },
    created() {
      window.this = this;
      window.isload = true;
           this.initData();
    },
    mounted() {
      if (this.$route.query.type != null && this.$route.query.type != "") {
        if (this.$route.query.type == "5") {//5 说明是查看
          $("input").attr("disabled", true);
          $(".text-left1").css("display", "none");
          $(".text-left5").css("display", "block");
          this.isEdit = true;
        }
      }
    },
    methods: {
      codeChange(index) {
        console.log(this.material);
        for (var i = 0; i < this.material.length; i++) {
          if (this.material[i].no === this.tableData[index].code) {
            this.tableData[index].code = this.material[i].no;
            this.tableData[index].name = this.material[i].name;
            for (var m = 0; m < this.tableData.length; m++) {
              if (this.material[i].label == this.tableData[m].id) {
                this.$message.info("本次添加含有重复原料");
                break;
              }
            }
            this.tableData[index].id = this.material[i].label;
            this.tableData[index].name = this.material[i].nameValue;
            this.tableData[index].code = this.material[i].no;
            this.tableData[index].spec = this.material[i].goodsSpec;
            this.tableData[index].unitName = this.material[i].purchaseUnit;
            this.tableData[index].purchaseSpec = this.material[i].purchaseSpec;
            this.tableData[index].price = (this.material[i].purchasePrice * 1).toFixed(2);
            this.tableData[index].count = 0;
            this.tableData[index].money = (this.tableData[index].price * this.tableData[index].count).toFixed(2);
            this.tableData[index].purchaseNewPrice = this.material[i].purchaseNewPrice;

            break;
          }
        }
      },
      remoteMethod(query) {
        if (query != '') {
          this.loading = true;
          this.$axios.get("materials/materials/getMaterialsByNameOrCode?name="+query).then(data=>{
            this.loading = false;
            if(data.status==200){
              var a=0;
              if(data.content.materialList && data.content.materialList.length>0){
                for(let i=0;i<data.content.materialList.length;i++){
                  a=0;
                  if(this.material && this.tableData && this.tableData.length>0 && this.tableData[0].id){
                    for(let s=0;s<this.material.length;s++){
                      if(this.material[s].id==data.content.materialList[i].id){
                        a++;
                      }
                    }
                    if(a<=0){
                      if(this.tableData[i].id){
                        this.material.push(data.content.materialList[i]);
                      }
                    }
                  }else{
                    this.material=data.content.materialList;
                  }
                }
              }else {
                this.material=data.content.materialList;
              }

            }
          });
        } else {
        }
      },
      getData(data){

        if(!this.material){
          this.material = [];
        }
        var a=0;
        for(var i=0;i<data.length;i++){
          a=0;
          for(let s=0;s<this.material.length;s++){
            if(this.material[s].id==data[i].id){
              a++;
            }
          }
          if(a<=0){
            data[i].value="["+data[i].no+"]"+data[i].name;
            this.material.push(data[i]);
          }
          this.tableData.push({
            id:data[i].id,
            code:data[i].no,
            name:data[i].name,
            spec:data[i].goodsSpec,
            purchaseSpec:data[i].purchaseSpec,
            unitName:data[i].purchaseUnit,
            count: '0',
            price: data[i].purchasePrice,
            purchaseNewPrice: data[i].purchaseNewPrice,
            money: '0.00',
            memo: '',
            value:"["+data[i].no+"]"+data[i].name
          });
        }
        for(var i=0;i<this.tableData.length;i++){
          if(this.tableData[i].purchaseNewPrice==null || this.tableData[i].purchaseNewPrice==''){
            this.tableData[i].purchaseNewPrice=this.tableData[i].purchasePrice;
          }
          if(this.tableData[i].id==''){
            this.tableData.splice(i,1);
          }
        }
        this.dialogTableVisible=false;
      },
      //页面第一次进来获取表单需要的数据
      initData() {
        var id = this.$route.query.id;
        var query = "";
        if (id != null && id != "") {
          query = "?id=" + id;
          this.modelForm.id = id;
        }
        this.$axios.get("branchstores/branchPurchaseOrders/create" + query).then((data)=> {
          if (data.status == 200) {
            let json = data.content;
            //初始化单据到表单
            this.modelForm = json.branchPurchaseOrder;
            if (id != null && id != "") {
              this.material=json.materials;
              for (var i = 0; i < json.detailList.length; i++) {
                for(var j=0;j<json.materials.length;j++){
                  if(json.detailList[i].specId==json.materials[j].label){
                    json.detailList[i].purchaseNewPrice=json.materials[j].purchaseNewPrice;
                  }
                }

                json.detailList[i].code = json.detailList[i].no;
                json.detailList[i].unitName = json.detailList[i].purchaseUnit;
                json.detailList[i].purchaseSpec = json.detailList[i].purchaseSpec;
                json.detailList[i].spec = json.detailList[i].materialSpec;
                json.detailList[i].id = json.detailList[i].specId ;
                json.detailList[i].name = json.detailList[i].name ;

                json.detailList[i].purchaseAmount = ( json.detailList[i].purchaseCount* json.detailList[i].purchasePrice*1).toFixed();
                json.detailList[i].sendAmount = ( json.detailList[i].sendCount* json.detailList[i].sendPrice*1).toFixed();
                if(json.detailList[i].acceptCount && json.detailList[i].acceptPrice){
                  json.detailList[i].acceptAmount = (json.detailList[i].acceptCount*json.detailList[i].acceptPrice*1).toFixed();
                }else {
                  json.detailList[i].acceptCount = 0;
                  json.detailList[i].acceptPrice = 0;
                  json.detailList[i].acceptAmount=0.0;
                }


              }
              this.tableData = json.detailList;
            }
          } else {
            this.$message.error(data.message);
          }
        })
      },
      checkboxInit(row, index) {
        console.log(row.state.key);
        if (row.state && row.state.key != "NORMAL") {
          return 0;//不可勾选
        } else {
          return 1;
        }
      },
      handleClose(done){
        this.$emit('close');
        done();
      },
      /* 打印单据 */
      printOrder() {
        // 打印预览
        var $this = this;
        setTimeout(function () {
          $this.Print($this.$refs.printData);
        }, 200);
      },

      printNum(){
        event.currentTarget.select();
      },
      handleIconClick(index) {
        if (this.isEdit) {
          return;
        }
        this.dialogTableVisible = true;
        this.itemActive = index;
      },
      selectGood(page) {
        this.dialogTableVisible = true;
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.selectGood("");
      },
      handleNodeClick(data) {
        var id = data.id;
        this.content = "search.category.id_eq=" + id + "";
        this.selectGood("");
      },
      newLabel(newList) {
        if (newList) {
          for (var i = 0; i < newList.length; i++) {
            newList[i].label = newList[i].name;
            if (newList[i].children) {
              this.newLabel(newList[i].children)
            }
          }
        }
      },
      goBack() {
        this.router.go(-1);
      },
      getSummaries(param) {
        const {columns, data} = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '合计';
            return;
          }
          if (index == 7 || index == 10) {
            const values = data.map(item => Number(item[column.property]));
            if (!values.every(value => isNaN(value))) {
              console.log("------- : "+sums[index]);
              sums[index] = values.reduce((prev, curr) => {
                const value = Number(curr);
                if (!isNaN(value)) {
                  if (index == 7 ) {
                    return prev + curr;
                  } else {
                    return ((prev * 1 + curr * 1) * 1).toFixed(2);
                  }
                } else {
                  if (index == 7) {
                    return prev;
                  } else {
                    return (prev * 1).toFixed(2);
                  }

                }
              }, 0);
            } else {
              sums[index] = '数据异常';
            }
          }
        });

        return sums;
      },
      getSummaries1(param) {
        const {columns, data} = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '合计';
            return;
          }
          if (index == 7 || index==9 || index == 10 || index==12 || index==13 || index==15) {
            const values = data.map(item => Number(item[column.property]));
            if (!values.every(value => isNaN(value))) {
              console.log("------- : "+sums[index]);
              sums[index] = values.reduce((prev, curr) => {
                const value = Number(curr);
                if (!isNaN(value)) {
                  if (index == 7 ) {
                    return prev + curr;
                  } else {
                    return ((prev * 1 + curr * 1) * 1).toFixed(2);
                  }
                } else {
                  if (index == 7) {
                    return prev;
                  } else {
                    return (prev * 1).toFixed(2);
                  }

                }
              }, 0);
            } else {
              sums[index] = '数据异常';
            }
          }
        });

        return sums;
      },
      submitForm(formName) {
        //console.log(this.tableData)
        this.type = 1;
        this.validateData(formName);
      },
      resetForm(formName) {
        this.type = 2;
        this.validateData(formName);
      },
      validateData(fromName) {
        if (this.modelForm.supplierId == null) {
          this.$message.error("请选择供应商！");
          return;
        }
        for (var i = 0; i < this.tableData.length; i++) {
          if (this.tableData[i].id == "") {
            if (this.tableData.length == 1) {
              this.$message.error("请添加单据明细！");
              return;
            }
            this.tableData.splice(i, 1);
            i--;
          }
            if (this.tableData[i].count <= 0) {
              this.$message.error("数量不能小于1！请检查第" + (i + 1) + "行数据");
              return;
            }

        }
        if (this.tableData == null || this.tableData.length == 0) {
          this.$message.error("请添加单据明细！");
          return;
        }
        if (this.$route.query.type == "4") {//5 说明是查看
          this.modelForm.id = "";
        }
        this.$refs[fromName].validate((valid) => {
          if (valid) {
            var data = {};
            for(var i=0;i<this.suppliers.length;i++){
              if(this.modelForm.supplierId==this.suppliers[i].id){
                this.modelForm.supplierName=this.suppliers[i].name
              }
            }
            data.type=this.type;
            data.purchaseOrder = this.modelForm;
            var tempData=[];
            console.log(this.tableData);
            for(let i=0;i<this.tableData.length;i++){
              tempData.push({
                specId:this.tableData[i].id,
                no:this.tableData[i].code,
                name:this.tableData[i].name,
                purchaseSpec:this.tableData[i].purchaseSpec,
                purchaseUnit:this.tableData[i].unitName,
                count:this.tableData[i].count,
                price:this.tableData[i].price,
                purchaseNewPrice:this.tableData[i].purchaseNewPrice,
                amount:this.tableData[i].money,
                remark:this.tableData[i].memo,
                spec:this.tableData[i].goodsSpec
              })
            }
            data.details = tempData;
            this.$axios.post("branchstores/branchPurchaseOrders/create", data, "json").then((data)=> {
              if (data.status == 200) {
                this.$message({
                  message: data.message,
                  type: 'success'
                });
                this.$emit('addSuccess');
                this.router.push({path: "/hqPurchaseOrders"});
              } else {
                this.$message.error(data.message);
              }
            })
          } else {
            this.$message.error("请检查输入项");
            return false;
          }
        });
      },
      priceValidate(item, key) {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
        if (!isNum.test(item[key])) {
          item[key] = "0.00"
        } else {
          item[key] = item[key]
        }
//        switch (key) {
//          case "count":
//            if (!isNaN(item.count)) {
//              item.money = item.price * item.count;
//              item.money = item.money.toFixed(2);
//            } else {
//              item.count = 0
//            }
//            break;
//          case "price":
//            if (!isNaN(item.price)) {
//              item.money = item.price * item.count;
//              item.money = item.money.toFixed(2);
//              item.price = (item.price * 1).toFixed(2);
//            } else {
//              item.price = '0.00';
//            }
//            break;
//          case "money":
//            if (!isNaN(item.money) && item.count > 0) {
//              item.price = item.money / item.count;
//              item.price = item.price.toFixed(2);
//              item.money = (item.money * 1).toFixed(2);
//            } else {
//              item.money = '0.00';
//            }
//            break;
//        }
      },
      handleCurrentChange(item) {
        this.currentPage3 = item;
        this.selectGood(item);
      },
      addColumn(index) {
        if (this.isEdit) {
          return;
        }
        this.tableData.splice(index + 1, 0, {
          id: '',
          code: '',
          name: '',
          goodsSpec: '',
          purchaseSpec: '',
          unitId: '',
          unitName: '',
          count: '0',
          price: '0.00',
          historyPrice: '',
          money: '0.00',
          memo: '',
        })
      },
      minusColumn(index) {
        if (this.isEdit) {
          return;
        }
        if (this.tableData.length > 1) {
          this.tableData.splice(index, 1);
        } else {
          this.$message.info("最少保留一条");
        }
      },
      handleSelect(item, index) {
        //console.log(this.tableData[index])
      },
    }

  }
</script>
<style scoped>
  .el-form-item {
    margin-bottom: 10px !important;
  }

  .el-table tr {
    border-bottom: 1px solid #dfe6ec !important;
  }

  .text-left5 {
    display: none;
  }

  /*单据打印*/
  :root {
    --zoomsize: 60%;
    --line-height-set: 30px;
  }

  .print-con {
    zoom: 60%;
    width: 98%;
    color: #333333;
    font-size: 12px !important;
    background-color: #ffffff;
    padding: 0 10px;
    position: absolute;
    left: 0;
    top: 0;
    z-index: -10;
  }

  /*单据-标题*/
  .print-con .order-title {
    zoom: var(--zoomsize);
    font-size: 12px;
    font-weight: bold;
    text-align: center;
    padding: 5px;
    border-bottom: 2px solid #333333;
  }

  /*单据-说明信息*/
  .print-con .order-info {
    padding: 0;
    font-size: 10px !important;
    height: auto;
    overflow: hidden;
  }

  .print-con .order-info ul {
    height: auto;
    overflow: hidden;
    margin: 0;
    padding: 0;
  }

  .print-con .order-info ul li {
    list-style: none;
    font-size: 12px;
  }

  .print-con .order-info ul li {
    zoom: var(--zoomsize);
    float: left;
    width: 33%;
    height: var(--line-height-set);
    line-height: var(--line-height-set);
    overflow: hidden;
  }

  .print-con .order-info ul li.sigle-line {
    zoom: var(--zoomsize);
    width: 100%;
    display: block;
  }

  /*单据-商品列表*/
  .print-con .tb-con {
    widht: 100%;
    background-color: #b4b4b4;
    border: 1px solid #b4b4b4;
  }

  .print-con .tb-con th {
    zoom: var(--zoomsize);
    height: var(--line-height-set);
    line-height: var(--line-height-set);
    background-color: #ffffff;
    border: 1px solid #b4b4b4;
    font-size: 12px;
  }

  .print-con .tb-con td {
    zoom: var(--zoomsize);
    height: var(--line-height-set);
    line-height: var(--line-height-set);
    text-align: center;
    background-color: #ffffff; /*border: 1px solid #b4b4b4;*/
    font-size: 12px;
  }

  /*责任条款*/
  .print-con .item-info {
  }

  .print-con .item-info ul {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .print-con .item-info ul li {
    zoom: var(--zoomsize);
    height: var(--line-height-set);
    line-height: var(--line-height-set);
    font-size: 12px;
  }

</style>
